home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Mail / Sources / UMailableDocument.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  7.5 KB  |  261 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UMailableDocument.cp 
  3. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #if qPowerTalk
  7.  
  8. #ifndef __UMAILABLEDOCUMENT__
  9. #include "UMailableDocument.h"
  10. #endif
  11.  
  12. // MacApp
  13.  
  14. #ifndef __UAPPLEEVENTS__
  15. #include "UAppleEvents.h"
  16. #endif
  17.  
  18. //    #ifndef __UAPPLICATION__
  19. //    #include "UApplication.h"
  20. //    #endif
  21.  
  22. #ifndef __UDISPATCHER__
  23. #include "UDispatcher.h"
  24. #endif
  25.  
  26. #ifndef __UFILE__
  27. #include "UFile.h"
  28. #endif
  29.  
  30. #ifndef __UMACAPPGLOBALS__
  31. #include "UMacAppGlobals.h"
  32. #endif
  33.     
  34. #ifndef __UMACAPPUTILITIES__
  35. #include "UMacAppUtilities.h"
  36. #endif
  37.     
  38. #ifndef __UMAILER__
  39. #include "UMailer.h"
  40. #endif
  41.  
  42. #ifndef __UWINDOW__
  43. #include "UWindow.h"
  44. #endif
  45.  
  46. // Toolbox
  47.  
  48. #ifndef __AEREGISTRY__
  49. #include <AERegistry.h>
  50. #endif
  51.  
  52. #ifndef __OCEERRORS__
  53. #include <OCEErrors.h>
  54. #endif
  55.  
  56. // ANSI
  57.  
  58. #ifndef __STDIO__
  59. #include <stdio.h>
  60. #endif
  61.  
  62. //========================================================================================
  63. // CLASS TMailableDocument
  64. //========================================================================================
  65. #undef Inherited
  66.  
  67. #pragma segment MAOpen
  68. #define Inherited TFileBasedDocument
  69.  
  70. MA_DEFINE_CLASS_M2(TMailableDocument, Inherited, MMailable);
  71.  
  72. //----------------------------------------------------------------------------------------
  73. // MMailable constructor
  74. //----------------------------------------------------------------------------------------
  75. #pragma segment MAOpen
  76.  
  77. TMailableDocument::TMailableDocument()
  78. {
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // TMailableDocument::IMailableDocument: 
  83. //----------------------------------------------------------------------------------------
  84. #pragma segment MAOpen
  85.  
  86. void TMailableDocument::IMailableDocument(TFile* itsFile, OSType itsScrapType)
  87. {
  88.     this->IFileBasedDocument(itsFile, itsScrapType);
  89.     
  90.     // Have letters default to the same creator as the regular file.
  91.     // We may be called with a null itsFile, in which case
  92.     // IFileBasedDocument may make the file for us. 
  93.     if (!itsFile)
  94.         itsFile = this->GetFile();
  95.     
  96.     if (itsFile)
  97.         this->fMailCreator = itsFile->fCreator;
  98.  
  99. } // TMailableDocument::IMailableDocument 
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // TMailableDocument::Close: 
  103. //----------------------------------------------------------------------------------------
  104. #pragma segment MARes
  105. void TMailableDocument::Close()    // override 
  106. {
  107.  
  108.     if (this->HasMailer())
  109.     {
  110.         TWindow* theWindowPtr = (TWindow *)fWindowList->First();
  111.         WindowRef theWindow = theWindowPtr->fWMgrWindow;
  112.         OSErr err = SMPPrepareToClose((WindowPtr)theWindow);
  113.         
  114.         if (err != noErr && err != kSMPNoMailerInWindow)
  115.         {
  116.             Failure(err,0);    
  117.         }
  118.     }
  119.     
  120.     Inherited::Close();
  121.         
  122. } // TMailableDocument::Close 
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // TMailableDocument::Changed: 
  126. //----------------------------------------------------------------------------------------
  127. #pragma segment MARes
  128. void TMailableDocument::Changed(ChangeID theChange,
  129.                                TObject* changedBy)    // override 
  130. {
  131.     Inherited::Changed(theChange, changedBy);
  132.     this->LetterContentChanged();
  133. } // TMailableDocument::Changed 
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // TMailableDocument::DoMenuCommand: 
  137. //----------------------------------------------------------------------------------------
  138. #pragma segment MASelCommand
  139.  
  140. void TMailableDocument::DoMenuCommand(CommandNumber aCommandNumber)
  141. {
  142.     if (!this->DoMailMenuCommand(aCommandNumber))
  143.         Inherited::DoMenuCommand(aCommandNumber);
  144. } // TMailableDocument::DoMenuCommand 
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // TMailableDocument::DoSetupMenus: 
  148. //----------------------------------------------------------------------------------------
  149. #pragma segment MADocumentRes
  150.  
  151. void TMailableDocument::DoSetupMenus()
  152. {
  153.     Inherited::DoSetupMenus();
  154.     this->DoSetupMailMenus();
  155. } // TMailableDocument::DoSetupMenus 
  156.  
  157. //----------------------------------------------------------------------------------------
  158. // TMailableDocument::DoAECreateElement: 
  159. //----------------------------------------------------------------------------------------
  160. #pragma segment MAScriptingRes
  161.  
  162. void TMailableDocument::DoAECreateElement(TAppleEvent* message,
  163.                                   TAppleEvent* reply)
  164. {
  165.     DescType theClass = message->ReadType(keyAEObjectClass);
  166.     if (theClass == cMailer)
  167.     {
  168.         if (!HasAOCEToolBox())
  169.             FailOSErr(errAEEventNotHandled);
  170.         this->DoAECreateMailer(message, reply);
  171.     }
  172.     else
  173.         TFileBasedDocument::DoAECreateElement(message, reply);
  174. } // TMailableDocument::DoAECreateElement 
  175.  
  176. //----------------------------------------------------------------------------------------
  177. // TMailableDocument::CountContainedObjects: 
  178. //----------------------------------------------------------------------------------------
  179. #pragma segment OSLDispatchRes
  180.  
  181. long TMailableDocument::CountContainedObjects(DescType desiredType)
  182. {
  183.     if (desiredType == cMailer)
  184.         return this->CountContainedMailers();
  185.     else
  186.         return TFileBasedDocument::CountContainedObjects(desiredType);
  187. } // TMailableDocument::CountContainedObjects 
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // TMailableDocument::GetIndContainedObject
  191. //----------------------------------------------------------------------------------------
  192. #pragma segment AMailerRes
  193.  
  194. MScriptableObject* TMailableDocument::GetIndContainedObject(DescType desiredType,
  195.                                                     long index)
  196. {
  197.     if (desiredType == cMailer)
  198.         return this->GetIndContainedMailer(index);
  199.     else
  200.         return TFileBasedDocument::GetIndContainedObject(desiredType, index);
  201. } // TMailableDocument::GetIndContainedObject
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // TMailableDocument::DoScriptCommand
  205. //----------------------------------------------------------------------------------------
  206. #pragma segment AMailerRes
  207.  
  208. void TMailableDocument::DoScriptCommand(CommandNumber aCommandNumber,
  209.                                         TAppleEvent* message,
  210.                                         TAppleEvent* reply)
  211. {
  212.     switch (aCommandNumber)
  213.     {
  214.         case cAESend:
  215.             this->DoAESend(message, reply);
  216.             break;
  217.             
  218.         default:
  219.             TFileBasedDocument::DoScriptCommand(aCommandNumber, message, reply);
  220.             break;
  221.     }
  222. } // TMailableDocument::DoScriptCommand
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // TMailableDocument::SaveDocument: 
  226. //----------------------------------------------------------------------------------------
  227. #pragma segment MAWriteFile
  228.  
  229. void TMailableDocument::SaveDocument(CommandNumber itsCommandNumber)// override 
  230. {
  231.     if (HasAOCEToolBox() && this->HasMailer())
  232.         this->fLetter->SaveLetter(itsCommandNumber);
  233.     else
  234.     {
  235.         TFile *theFile = this->fFile;
  236.         
  237.         Inherited::SaveDocument(itsCommandNumber);
  238.         
  239.         FInfo finderInfo;
  240.         FXInfo xFinderInfo;
  241.         Boolean isDirectory;
  242.  
  243.         OSErr theErr = theFile->GetFinderInfo(finderInfo, xFinderInfo, isDirectory);
  244.         if (theErr == noErr && !isDirectory)
  245.         {
  246.             if (finderInfo.fdType == kStandardLetterFileType)
  247.             {
  248.                 finderInfo.fdType = gDispatcher->fMainFileType;
  249.                 theFile->SetFinderInfo(finderInfo);
  250.             }
  251.         }
  252.     }
  253. } // TMailableDocument::SaveDocument 
  254.  
  255. #endif // qPowerTalk
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // End of UMailableDocument.cp
  259.  
  260. #pragma segment Inline
  261.